import serial, time
spi=serial.Serial("/dev/ttyACM0", 38400, timeout=0)
print "SPI ISS"
# Config SPI ISS
# x90 valide pour config CPHA=LPC_SPI->&=~(1<<3) et CPOL=LPC_SPI->&=~(1<<4)
# x01 = 3 MHz, 0xff = 23.44 KHz clock
mode=b'\x5a\x02\x90\x01' 
spi.write(mode)
spi.flush()
time.sleep(0.1)
rep=spi.read(2)
print "Byte 1=", ord(rep[0]) , " Byte 2=", ord(rep[1])
if ( (ord(rep[0]) == 255) and (ord(rep[1]) == 0) ):
    print "ACK OK"
else:
    print "! NOT ACKN" 
msg = b'\x61\x0a\x01\x02\x03\x04\x05\x06\x07\x08\x09\x0a'
spi.write(msg)  
spi.flush()
time.sleep(0.01)
rep=spi.read(2)
print "Byte 1=", ord(rep[0]) , " Byte 2=", ord(rep[1])
if ( (ord(rep[0]) == 255) ):
    print "ACK OK"
else:
    print "! NOT ACKN" 
time.sleep(0.5)
spi.close()
print "done"
